module.exports = (req, res, next) => {
    let { flag } = req.body;
    let path = req.path.toLowerCase();
    // 放行路由 register注册路由
    let unPermissionPath = [`/login`, `/logout`, `/dologin`, `/ajaxlogin`, `/register`, `/ajaxregister`, `/ajaxemail`]
    if (!unPermissionPath.includes(path)) {
        if (req.session.userInfo) {
            next();
        } else {
            if (flag === `ajax`) {
                res.json({
                    code: 30004,
                    message: `请重新登录`
                })
                return;
            } else {
                res.redirect(`/login`);
                return;
            }
        }
    } else {
        next();
    }
}